import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.stream.Stream;

public class JdbcDemo08 {
    public static void main(String[] args) throws IOException, SQLException {
        String sql = "insert into article values(0,?,?)";
        PreparedStatement ps = JDBCUtil1.getStatement(sql);
        FileReader fileReader = new FileReader("F:\\IdeaProjects\\MyJava230203\\JDBC_Demo\\src\\data.txt");
        char[] chars = new char[1024];
        StringBuilder sb = new StringBuilder();
        int count;
        while ((count = fileReader.read(chars)) != -1) {
            sb.append(new String(chars, 0, count));
        }

        String[] contents = sb.toString().split("\\r");
        for (String c : contents) {
            String[] title_content = c.split(";");
            if (title_content.length == 2) {
                ps.setString(1, title_content[0]);
                ps.setString(2, title_content[1]);
                ps.executeUpdate();
            }
        }



        fileReader.close();
        ps.close();

    }
}
